<#assign path=request.contextPath>
<#assign basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/">

<!DOCTYPE html>
<html>
<head>
<title>WebDesign Admin - Home</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- bootstrap -->
<link href="${path}/css/bootstrap/bootstrap.css" rel="stylesheet" />
<link href="${path}/css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
<link href="${path}/css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

<!-- libraries -->
<link href="${path}/css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

<!-- global styles -->
<link rel="stylesheet" type="text/css" href="${path}/css/layout.css" />
<link rel="stylesheet" type="text/css" href="${path}/css/elements.css" />
<link rel="stylesheet" type="text/css" href="${path}/css/icons.css" />

<!-- this page specific styles -->
<link rel="stylesheet" href="${path}/css/compiled/tables.css" type="text/css" media="screen" />
<link rel="stylesheet" href="${path}/css/compiled/index.css" type="text/css" media="screen" />
<link href="${path}/css/compiled/teacherhome.css" rel="stylesheet" type="text/css">


<!-- open sans font -->
<link href='http://fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800'
	rel='stylesheet' type='text/css' />


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

	<!-- navbar -->
	<div class="navbar navbar-inverse">
		<div class="navbar-inner">
			<a class="brand" href="index.html"><img
				src="${path}/img/logo-login.png" /></a>

						<ul class="nav pull-right">
				<!--无序列表-->
				 <li>
				 	<#if termid?exists>
                		<a href="${path}/teacher/selectTerm?terminfo=${termid}">
                	</#if>
                   	${username}
                	</a>
            	</li>
				<div class="copyrights"></div>

				<li class="hidden-phone">
                    <a href="${path}/teacher/showRewrite">修改密码</a>
                </li>

                <li class="hidden-phone">
                    <a href="${path}/common/logout">注销</a>
                </li>
			</ul>
		</div>
	</div>
	<!-- end navbar -->

	<!-- sidebar -->
	<div id="sidebar-nav">
		<ul id="dashboard-menu">
			 <li>     
              <font size=3><b>           
             <#if termname?exists>
              	${termname}
             </#if>
              </b></font>
		    </li>
			<li class="active">
				<div class="pointer">
					<div class="arrow"></div>
					<div class="arrow_border"></div>
				</div> <a href="${path}/teacher/showTermAndHomework"> <i class="icon-home"></i>
							<span>教师主页</span>
					   </a>
			</li>

			<li><a href="${path}/teacher/assignHomework"> <i
					class="icon-edit"></i> <span>作业发布</span>
			</a></li>

			<li><a href="${path}/teacher/TermSum"> <i
					class="icon-signal"></i> <span>作业查看</span>
			</a></li>


			<li><a href="${path}/common/homeworkDisplay"> <i class="icon-picture"></i>
					<span>作业展示</span>
			</a></li>

			<li>
				<a class="dropdown-toggle" href="#"> 
					<i class="icon-group"></i> <span>学生/学年管理</span> 
					<i class="icon-chevron-down"></i>
				</a>
				<ul class="submenu">
					<li><a href="${path}/teacher/terms">新建学年</a></li>
					<li><a href="${path}/teacher/showUsers">密码重置</a></li>
				</ul>
			</li>
	</div>
	<!-- end sidebar -->


	<!-- main container -->
	<div class="content">
	<form action="#" method="post" id="form1">
		<div class="container-fluid">
			<!-- table sample -->
			<!-- the script for the toggle all checkboxes from header is located in js/theme.js -->
			<div class="table-products section">
				<div class="pull-left">
						<div class="ui-select">
							<select name="terminfo">
							<#if termid?exists>
								<#list terms as term>
									<#if term.termid == Session["termid"]>
										<option value=${term.termid} selected="selected" />${termname}
									<#else>
    									<option value=${term.termid} />${term.termname}
        							</#if>
								</#list>
							
								<#else>
								<option value="#" selected="selected">------请选择学年-------</option>
								<#list terms as term>
									<option value=${term.termid} />${term.termname}
								</#list>
							</#if>
							</select>
						</div>
						<input type="button" id="select" value="确定" class="btn-flat white">
					</div>
				<#if termid?exists&&homeworks?exists>
				<div class="row-fluid">
					<table class="table table-hover">
						<thead>
							<tr>
								<th class="span3">作业</th>
								<th class="span3"><span class="line"></span>描述</th>
								<th class="span3"><span class="line"></span>状态</th>
								<th class="span3"><span class="line"></span>开始时间</th>
								<th class="span3"><span class="line"></span>结束时间</th>
								<th class="span3"><span class="line"></span>已交人数</th>
								<th class="span3"><span class="line"></span>未交人数</th>
							</tr>
						</thead>
						<tbody id="content">
							<!-- row -->
							<#list homeworks as homework>
								<tr>
									<td>
										<p>
											${homework.title}
										</p>
									</td>
									<td>
										<p class="nop">
											<nobr>${homework.description}</nobr>
										</p>
									</td>
									<td><#if homework.state == 1>
											<span class="label label-success">进行中</span>
										<#elseif homework.state == 0>
											<span class="label label-info">未开始</span>
										<#elseif homework.state == 2>
											<span class="label label-info">已结束</span>
										</#if>
										
									</td>
									<td>
										<p>
											${homework.starttime?string('yyyy-MM-dd HH:mm:ss')}
										</p>
									</td>
									<td>
										<p>
											${homework.endtime?string('yyyy-MM-dd HH:mm:ss')}
										</p>
									</td>
									<td>

										<#if homework.submitnum == 0>
											<p>
                                				${homework.submitnum}
											</p>
										<#else>
											<p>
												<a href="${path}/teacher/showHomework?homeworkid=${homework.homeworkid}">
                                					${homework.submitnum}
                                				</a>
											</p>
										</#if>
									</td>
									<td>
										<#if homework.unsubmitnum == 0>
											<p>
                                				${homework.unsubmitnum}
											</p>
										<#else>
											<p>
												<a href="${path}/teacher/showUnfinishHomework?homeworkid=${homework.homeworkid}">
                                					${homework.unsubmitnum}
                                				</a>
											</p>
										</#if>
										
										<ul class="actions">
											<li>
											<a href="${path}/teacher/showHomeworkInfo?homeworkid=${homework.homeworkid}">
											<i class="table-edit"></i></a></li>
											<!--编辑作业-->
											
											<li class="last">
												<a href="#" onclick="deleteHomework('${homework.homeworkid}')">
													<i class="table-delete">
													</i>
												</a>
											</li>
												
											<!--删除作业-->
										</ul>
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
				</div>
				<div class="table-products pagination">
      				<font class="title">共</font>
      					${page.totalPages}<font class="title">页　当前第 </font> 
     					<span id="number">${page.number}</span><font class="title">页</font>
     				<input type="hidden" id="pagenumber" value="${page.number}"/>
     				<input type="hidden" id="pagecount" value="${page.totalPages}"/>
      				<input type="button" class="btn-flat white" id="sy"  onclick="selectSy()" value="首页"/>  
      				<input type="button" class="btn-flat white" id="syy" onclick="selectSyy()" value="上一页 "/>  
      				<input type="button" class="btn-flat white" id="xyy" onclick="selectXyy()" value="下一页"/>  
      				<input type="button" class="btn-flat white" id="wy"  onclick="selectWy()" value="尾页 "/>  
      			</div>
				</#if>
				
				<div id="photo-list">  
				    <ul id="scroll">  
				      <li>
				        <a href="#" title="1312190303_郑晓玲">
				          <img src="${path}/img/8.jpg"  alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190304_席晶">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190125_唐敏意">
				          <img src="${path}/img/8.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190306_李敏">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190304_席晶">
				          <img src="${path}/img/8.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190303_郑晓玲">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li>    
				      <li>
				        <a href="#" title="1312190125_唐敏意">
				          <img src="${path}/img/8.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190306_李敏">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190304_席晶">
				          <img src="${path}/img/8.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190125_唐敏意">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190303_郑晓玲">
				          <img src="${path}/img/8.jpg" alt=""/>
				        </a>
				      </li>  
				      <li>
				        <a href="#" title="1312190306_李敏">
				          <img src="${path}/img/7.jpg" alt=""/>
				        </a>
				      </li> 
				    </ul> 
			  	</div>
			</div>
		</div>
	</form>
	</div>
</body>

		<!-- scripts -->
		<script src="${path}/js/jquery-latest.js"></script>
		<script src="${path}/js/bootstrap.min.js"></script>
		<script src="${path}/js/theme.js"></script>
		<script src="${path}/js/jquery.cookie.js"></script>
		<script type="text/javascript" src="${path}/js/rlslide.js"></script>
		
		<script type="text/javascript">
		<#if termid?exists&&homeworks?exists>
		//分页，应该传递pageCount
		 function selectSy(){
		  	var page = parseInt($("#pagenumber").val());
             var pageCount = parseInt($("#pagecount").val());
             if(pageCount==0){  
                 alert("当前无数据");  
             }else if(page==1){     
                 alert("当前已是第一页");  
             } else {
             	redirectPage(1);
             	$.cookie("pagenumber", 1); 
             	document.getElementById("number").innerText = 1;
             	$("#pagenumber").val(1);
             }
         }
          function selectSyy(){ 
          	 var page = parseInt($("#pagenumber").val());
             var pageCount = parseInt($("#pagecount").val());
             if(pageCount==0){  
                 alert("当前无数据");  
             }else if(page==1){     
                 alert("当前已是第一页");  
             } else{  
               redirectPage(page-1);
               $.cookie("pagenumber",page - 1); 
               document.getElementById("number").innerText = page - 1;
               $("#pagenumber").val(page - 1);
             } 
         }  
         function selectXyy(){ 
         	var page = parseInt($("#pagenumber").val());
             var pageCount = parseInt($("#pagecount").val());
             if(pageCount==0){  
                 alert("当前无数据");  
             }else if(page==pageCount){  
                 alert("当前已是最后一页");  
             }else{  
               redirectPage(page+1);
               $.cookie("pagenumber", page+1);
               document.getElementById("number").innerText = page + 1;
               $("#pagenumber").val(page + 1);
             }
         }  
         function selectWy(){
         	 var page = parseInt($("#pagenumber").val());
             var pageCount = parseInt($("#pagecount").val());
             if(pageCount==0){  
                 alert("当前无数据");  
             }else if(page==pageCount){  
                 alert("当前已是最后一页");  
             }else{ 
             	 redirectPage(pageCount);
             	 $.cookie("pagenumber", pageCount); 
             	 document.getElementById("number").innerText = pageCount;
             	 $("#pagenumber").val(pageCount);
             }
         }
         
         
         function redirectPage(numpage){
         	$.ajax({
          		url:"${path}/ateacher/showTermAndHomework",
          		data:{numpage:numpage},
          		type:"post",
          		dataType:"json",
          		error:function(){
          			alert("请求错误！");
          		},
          		success:function(responseResult){
          			if(responseResult.homeworks != null){
          				innerHtml(responseResult.homeworks);
          			}
          		}
          		
          	});
         }
         
          function deleteHomework(homeworkid){  
          	$.ajax({
          		url:"${path}/ateacher/delateHomework",
          		data:{homeworkid:homeworkid},
          		type:"post",
          		dataType:"json",
          		error:function(){
          			alert("请求错误！");
          		},
          		success:function(responseResult){
          			if(responseResult.homeworks != null){
          				innerHtml(responseResult.homeworks);
          				
          			}else{
          				alert("删除失败！");
          			}
          		}
          		
          	});
            
         }  
         
         function innerHtml(data){
         	var html = "";
         	for(var i=0 ; i<data.length ; i++){
         		html += "<tr>";
         		html += "<td><p>"+data[i].title+"</p></td>";
         		html += "<td><p class='nop'><nobr>"+data[i].description+"</nobr></p></td>";
         		
         		if(data[i].state==1){html += "<td><span class='label label-success'>进行中</span></td>";}
         		else if(data[i].state==0){html +="<td><span class='label label-info'>未开始</span></td>";}
         		else{ html +="<td><span class='label label-info'>已结束</span></td>";}
         		
         		html += "<td><p>"+data[i].starttime+"</p></td>";
         		html += "<td><p>"+data[i].endtime+"</p></td>";
         		
         		if(data[i].submitnum == 0){html += "<td><p>0</p></td>";}
				else{html += "<td><p><a href='${path}/teacher/showHomework?homeworkid="+data[i].homeworkid+"'>"+data[i].submitnum+"</a></p></td>";}
				
				if(data[i].unsubmitnum == 0){html += "<td><p>0</p>";}
				else{html += "<td><p><a href='${path}/teacher/showUnfinishHomework?homeworkid="+data[i].homeworkid+"'>"+data[i].unsubmitnum+"</a></p>";}

				html += "<ul class='actions'><li><a href='${path}/teacher/showHomeworkInfo?homeworkid="+data[i].homeworkid+"'><i class='table-edit'></i></a></li>";
         		html += "<li class='last'><a href='${path}/teacher/delateHomework?homeworkid="+data[i].homeworkid+"'><i class='table-delete'></i></a></li></ul></td>";
         		html += "</tr>";
         		
         	}
         	document.getElementById("content").innerHTML = html;
         }
        </#if>
        $("#select").click(function(){
			 form1.action = "${path}/teacher/selectTerm";  
        	 form1.submit();
         });
     
		</script>
	
</html>